package org.hnxxxy.ebms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hnxxxy.ebms.common.Result;
import org.hnxxxy.ebms.pojo.Plan;
import org.hnxxxy.ebms.service.PlanService;
import org.hnxxxy.ebms.vo.PlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WANGWEI
 * @since 2021-06-10
 */
@RestController
@RequestMapping("/plan")
public class PlanController {

    @Autowired
    private PlanService planService;

    @PostMapping("/add")
    @ApiOperation(value = "增加招生计划")
    public Result<String> addPlan(@RequestBody Plan plan){
        return planService.add(plan);
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除招生计划")
    public Result<String> delPlan(@PathVariable("id") Integer id){
        if (planService.removeById(id)){
            return Result.success(200,"删除成功");
        }
        return Result.fail("删除失败");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改招生计划")
    public Result<String> updatePlan(@RequestBody Plan plan){
        if (planService.updateById(plan)){
            return Result.success(200,"修改成功");
        }
        return Result.fail("删除失败");
    }

    @GetMapping("/get")
    @ApiOperation(value = "查询招生计划")
    public Result<Plan> getPlan(){
        return planService.getPlans();
    }

    @GetMapping("/tea/get/{page}")
    @ApiOperation(value = "查询招生计划")
    public Result<IPage<PlanVo>> getTeaPlan(@PathVariable("page") int page){
        return planService.getTeaPlans(page);
    }


    @GetMapping("/tea/getName/{name}/{page}")
    @ApiOperation(value = "根据姓名搜索")
    public Result<IPage<PlanVo>> getTeaPlanByName(@PathVariable("name") String name,@PathVariable("page") int page){
        return planService.getTeaPlanByName(name,page);
    }

}
